<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
    protected $result;
    protected $pagination;
    
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
       $model = $this->getModel();
       $aut = new bgAuthorize(); 
       
        switch(JRequest::getVar('task')){
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                JToolBarHelper::title('市町村情報作成', 'city.png');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a01120');
                
                break;
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }
                else{
                    die("データは見つかりませんでした");
                }
                $aut=new bgAuthorize();
                //check center_Code for user login
                 $group=$aut->getUserGroup();
                 if($group==9||$group==8)
                 {
                    JToolBarHelper::save2copy('savetemp','一時保存');
                 }
                JToolBarHelper::title('市町村情報編集', 'city.png');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a01120');
                break;
            case 'add':
            	JToolBarHelper::title('市町村情報作成', 'city.png');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a01110');
            	break;
            default :
                //Kiem tra co quyen Editx`
                if($aut->checkEditOwn() == 1){
                    $this->result = &$model->getTown($aut->getOCBA_CODE());
                }else{
                    $this->result = &$model->getTown();
                }
                $this->pagination = &$model->getPagination();
            	JToolBarHelper::title( '市町村情報管理', 'city.png');
                
                if($aut->checkAdd()){
                    JToolBarHelper::addNew('add','作成');
                }
                
                if($aut->checkEdit() || $aut->checkEditOwn()){
                    JToolBarHelper::editList('edit', '編集');
                }
                
                if($aut->checkDelete()){
                    JToolBarHelper::deleteList('', 'remove','削除');
                }
                
	            if($aut->getUserGroup() == '8' || $aut->getUserGroup() == '9'){
	               JToolBarHelper::custom('export_csv','csv.png','CSV出力', 'CSV出力',false);
	            }
                $this->setLayout('a01100');
		}
		parent::display();
	}
}